package com.panghl.report;

import net.sf.jasperreports.engine.*;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author panghl
 * @Date 2022/3/3
 * @Description 导出 pdf
 **/
public class PDFDemo {
    public static void main(String[] args) throws FileNotFoundException, JRException {
        // 模板文件
        String filePath = "D:\\test01.jasper";
        FileInputStream inputStream = new FileInputStream(filePath);

        Map<String,Object> params = new HashMap<>();
        params.put("userNameP","张三吗？");
        params.put("phoneP","13123123123");
        JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, params, new JREmptyDataSource());

        JasperExportManager.exportReportToPdfStream(jasperPrint,new FileOutputStream("D:\\1.pdf"));
    }
}
